#ifndef _TOKEN_
#define _TOKEN_

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include <openssl/hmac.h>
#include <openssl/evp.h>
#include <openssl/sha.h>
#include <openssl/rand.h>
#include <openssl/bio.h>
#include <openssl/buffer.h>
#include <jansson.h>
#include "threadPool.h"
#include "protocol.h"

#define SECRET_KEY "your_secure_secret_key_here" 
#define TOKEN_EXPIRY 1800 // Token有效期30分钟

// Base64编码表
static const char base64_table[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";


int base64_encode(const char *input, char *output, size_t output_len);

int base64_decode(const char *input, char *output, size_t output_len);

// 生成JWT Token
char* generate_jwt(const char *username);

// 验证JWT Token
int verify_jwt(const char *token, char *username, ssize_t username_size);

int verify_token_auth(int sockfd, protocol_header_t *header);
#endif
